package com.sfzlot.dev.netty.server.server.encode;

import com.sfzlot.dev.netty.bean.Message;
import com.sfzlot.dev.netty.utils.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class Encoder extends MessageToByteEncoder<Message> {
	
	final static Logger logger = LoggerFactory.getLogger(Encoder.class);
	
    @Override  
    protected void encode(ChannelHandlerContext ctx, Message message, ByteBuf out){  
    	out.writeBytes(MessageUtils.getBytes(message));
        //打印日志
        String msg = ByteBufUtil.hexDump(out);
        logger.info("发出的报文信息为:{}", msg);
       //MessageSender.writerMessageLong(msg + "_" + System.currentTimeMillis());
       // MessageSender.sendMessageQueue(msg + "_" + System.currentTimeMillis());
    }  
} 
